(async function(){
    await findjob()
    console.log('trip')
})()

async function findjob(){
    try{
        await interview(1);
        await interview(2);
        await interview(3);
        try {
            await Promise.all([
                family('father').catch(() => {
                        console.log('老爸说的听听就行了') }),
                family('mother'),
                family('wife'),
            ])
        } catch (error) {
            error.round = 'family'
        }
        console.log('all pass,all agree, just smile')
    } catch(error){
        console.log('cry ar '+ error.round)
    }
}


/**
 * 进行第round轮面试
 */
function interview(round) {
    return new Promise((resolve, reject) => {
        setTimeout(() => {
            if (Math.random() < 0.2) {
                const error = new Error('failed');
                error.round = round;
                reject(error);

            } else {
                resolve('success');
            }
        }, 500)
    })
}
/**
 * 寻求家人的意见确定要不要接受offer
 */
function family(name) {
    return new Promise((resolve, reject) => {
        setTimeout(() => {
            if (Math.random() < 0.2) {
                const error = new Error('disagree');
                error.name = name;
                reject(error);

            } else {
                resolve('agree');
            }
        }, Math.random() * 400)
    })
}